#include "gui-demo.h"

struct _GuiWindow
{
        AdwApplicationWindow parent_instance;
};

G_DEFINE_FINAL_TYPE(GuiWindow, gui_window, ADW_TYPE_APPLICATION_WINDOW)

static void
gui_window_finalize(GObject *object)
{
        G_OBJECT_CLASS(gui_window_parent_class)->finalize(object);
}

static void
gui_window_class_init(GuiWindowClass *klass)
{
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);

        gtk_widget_class_set_template_from_resource(widget_class,
                                                "/org/gui/demo/interface.xml");
        
        G_OBJECT_CLASS(klass)->finalize = gui_window_finalize;
}

static void
gui_window_init(GuiWindow *self)
{
        gtk_widget_init_template(GTK_WIDGET(self));
}

static void
gui_demo_activate(AdwApplication *app, gpointer data)
{
        GtkWindow *window;

        window = gtk_application_get_active_window(GTK_APPLICATION(app));

        if (window == NULL) {
                window = g_object_new(GUI_TYPE_WINDOW,
                                      "application",
                                      app, NULL);
        }

        gtk_window_present(window);
}

int main(int argc, char *argv[])
{
        g_autoptr(AdwApplication) app = 
                adw_application_new("org.gui.demo", G_APPLICATION_DEFAULT_FLAGS);
        g_signal_connect(app, "activate", G_CALLBACK(gui_demo_activate), NULL);
        return g_application_run(G_APPLICATION(app), argc, argv);
}
